<?php 
class Schedule_Model_DbTable_DbSchedule extends Zend_Db_Table_Abstract{
	//protected $_name = "tbl_schedule";
	public function addSchedule($data){
		$db= $this->getAdapter();
		$db->beginTransaction();
		try {
			$shedule = array(
					"department_id"		=>	$data["deparment"],
					"fac_id"			=>	$data["facuty"],
					"semester_id"		=>	$data["semester"],
					"year_id"			=>	$data["year"],
					"academic_year"		=>	$data["academic_year"],
					"session_id"		=>	$data["session"],
					"room_id"			=>	$data["room_pri"],
					"description"		=>	"",
					"created_date"		=>	new Zend_Date(),
					"valid_date"		=>	"",
					"created_by"		=>	1
			);
			$this->_name="tbl_schedules";
			$shedules = $this->insert($shedule);
			
			$session = $data["session"];
			
			// Subject Section
			
			if($session==1){
				$db->getProfiler()->setEnabled(true);
				$subject = array(
						"sche_id"					=>		$shedules,
							
						"mon_7_8"					=>		$data["subject_mon_7_8"],
						"mon_8_10"					=>		$data["subject_mon_8_10"],
						"mon_10_12"					=>		$data["subject_mon_10_12"],
							
						"tur_7_8"					=>		$data["subject_tue_7_8"],
						"tur_8_10"					=>		$data["subject_tue_8_10"],
						"tur_10_12"					=>		$data["subject_tue_10_12"],
							
						"wed_7_8"					=>		$data["subject_wed_7_8"],
						"wed_8_10"					=>		$data["subject_wed_8_10"],
						"wed_10_12"					=>		$data["subject_wed_10_12"],
			
						"thu_7_8"					=>		$data["subject_thu_7_8"],
						"thu_8_10"					=>		$data["subject_thu_8_10"],
						"thu_10_12"					=>		$data["subject_thu_10_12"],
			
						"fri_7_8"					=>		$data["subject_fri_7_8"],
						"fri_8_10"					=>		$data["subject_fri_8_10"],
						"fri_10_12"					=>		$data["subject_fri_10_12"],
				);
					
				$this->_name="tbl_subject_sche";
				$this->insert($subject);
					
				Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
				Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
				$db->getProfiler()->setEnabled(false);
				//exit();
			}elseif ($session==2){
				$subject = array(
						"sche_id"					=>		$shedules,
							
						"mon_1_2"					=>		$data["subject_mon_1_2"],
						"mon_2_4"					=>		$data["subject_mon_2_4"],
						"mon_4_5"					=>		$data["subject_mon_4_5"],
							
						"tur_1_2"					=>		$data["subject_tue_1_2"],
						"tur_2_4"					=>		$data["subject_tue_2_4"],
						"tur_4_5"					=>		$data["subject_tue_4_5"],
							
						"wed_1_2"					=>		$data["subject_wed_1_2"],
						"wed_2_4"					=>		$data["subject_wed_2_4"],
						"wed_4_5"					=>		$data["subject_wed_4_5"],
							
						"thu_1_2"					=>		$data["subject_thu_1_2"],
						"thu_2_4"					=>		$data["subject_thu_2_4"],
						"thu_4_5"					=>		$data["subject_thu_4_5"],
							
						"fri_1_2"					=>		$data["subject_fri_1_2"],
						"fri_2_4"					=>		$data["subject_fri_2_4"],
						"fri_4_5"					=>		$data["subject_fri_4_5"],
							
				);
				$this->_name="tbl_subject_sche";
				$this->insert($subject);
			}elseif ($session==3){
				$subject = array(
						"sche_id"					=>		$shedules,
							
						"mon_5_7"					=>		$data["subject_mon_5_7"],
						"mon_7_8_1"					=>		$data["subject_mon_7_8_1"],
							
						"tur_5_7"					=>		$data["subject_tue_5_7"],
						"tur_7_8_1"					=>		$data["subject_tue_7_8_1"],
							
						"wed_5_7"					=>		$data["subject_wed_5_7"],
						"wed_7_8_1"					=>		$data["subject_tue_7_8_1"],
							
						"thu_5_7"					=>		$data["subject_thu_5_7"],
						"thu_7_8_1"					=>		$data["subject_thu_7_8_1"],
							
						"fri_5_7"					=>		$data["subject_fri_5_7"],
						"fri_7_8_1"					=>		$data["subject_fri_7_8_1"],
				);
				$this->_name="tbl_subject_sche";
				$this->insert($subject);
			}else{
					
				$subject =array(
						"sche_id"					=>		$shedules,
						"sat_7_8"					=>		$data["subject_sat_7_8"],
						"sat_8_10"					=>		$data["subject_sat_8_10"],
						"sat_10_12"					=>		$data["subject_sat_10_12"],
						"sat_1_2"					=>		$data["subject_sat_1_2"],
						"sat_2_4"					=>		$data["subject_sat_2_4"],
						"sat_4_5"					=>		$data["subject_sat_4_5"],
						"sat_5_7"					=>		$data["subject_sat_5_7"],
						"sat_7_8_1"					=>		$data["subject_sat_7_8_1"],
							
						"sun_7_8"					=>		$data["subject_sun_7_8"],
						"sun_8_10"					=>		$data["subject_sun_8_10"],
						"sun_10_12"					=>		$data["subject_sun_10_12"],
						"sun_1_2"					=>		$data["subject_sun_1_2"],
						"sun_2_4"					=>		$data["subject_sun_2_4"],
						"sun_4_5"					=>		$data["subject_sun_4_5"],
						//"sun_5_7"					=>		$data["subject_sun_5_7"],
						"sun_7_8_1"					=>		$data["subject_sat_7_8_1"],
						"created_date"				=>		new Zend_Date(),
				);
				$this->_name="tbl_subject_sche";
				$this->insert($subject);
			}
			
			
			// Teacher Section
			
			if($session==1){
				$teacher = array(
						"sche_id"					=>		$shedules,
			
						"mon_7_8"					=>		$data["teacher_mon_7_8"],
						"mon_8_10"					=>		$data["teacher_mon_8_10"],
						"mon_10_12"					=>		$data["teacher_mon_10_12"],
			
						"tur_7_8"					=>		$data["teacher_tue_7_8"],
						"tur_8_10"					=>		$data["teacher_tue_8_10"],
						"tur_10_12"					=>		$data["teacher_tue_10_12"],
			
						"wed_7_8"					=>		$data["teacher_wed_7_8"],
						"wed_8_10"					=>		$data["teacher_wed_8_10"],
						"wed_10_12"					=>		$data["teacher_wed_10_12"],
			
						"thu_7_8"					=>		$data["teacher_thu_7_8"],
						"thu_8_10"					=>		$data["teacher_thu_8_10"],
						"thu_10_12"					=>		$data["teacher_thu_10_12"],
			
						"fri_7_8"					=>		$data["teacher_fri_7_8"],
						"fri_8_10"					=>		$data["teacher_fri_8_10"],
						"fri_10_12"					=>		$data["teacher_fri_10_12"],
				);
			
				$this->_name="tbl_teacher_sche";
				$this->insert($teacher);
			}elseif ($session==2){
				$teacher = array(
						"sche_id"					=>		$shedules,
			
						"mon_1_2"					=>		$data["teacher_mon_1_2"],
						"mon_2_4"					=>		$data["teacher_mon_2_4"],
						"mon_4_5"					=>		$data["teacher_mon_4_5"],
			
						"tur_1_2"					=>		$data["teacher_tue_1_2"],
						"tur_2_4"					=>		$data["teacher_tue_2_4"],
						"tur_4_5"					=>		$data["teacher_tue_4_5"],
			
						"wed_1_2"					=>		$data["teacher_wed_1_2"],
						"wed_2_4"					=>		$data["teacher_wed_2_4"],
						"wed_4_5"					=>		$data["teacher_wed_4_5"],
			
						"thu_1_2"					=>		$data["teacher_thu_1_2"],
						"thu_2_4"					=>		$data["teacher_thu_2_4"],
						"thu_4_5"					=>		$data["teacher_thu_4_5"],
			
						"fri_1_2"					=>		$data["teacher_fri_1_2"],
						"fri_2_4"					=>		$data["teacher_fri_2_4"],
						"fri_4_5"					=>		$data["teacher_fri_4_5"],
			
				);
				$this->_name="tbl_teacher_sche";
				$this->insert($teacher);
			}elseif ($session==3){
				$teacher = array(
						"sche_id"					=>		$shedules,
			
						"mon_5_7"					=>		$data["teacher_mon_5_7"],
						"mon_7_8_1"					=>		$data["teacher_mon_7_8_1"],
			
						"tur_5_7"					=>		$data["teacher_tue_5_7"],
						"tur_7_8_1"					=>		$data["teacher_tue_7_8_1"],
			
						"wed_5_7"					=>		$data["teacher_wed_5_7"],
						"wed_7_8_1"					=>		$data["teacher_tue_7_8_1"],
			
						"thu_5_7"					=>		$data["teacher_thu_5_7"],
						"thu_7_8_1"					=>		$data["teacher_thu_7_8_1"],
			
						"fri_5_7"					=>		$data["teacher_fri_5_7"],
						"fri_7_8_1"					=>		$data["teacher_fri_7_8_1"],
				);
				$this->_name="tbl_teacher_sche";
				$this->insert($teacher);
			}else{
			
				$teacher =array(
						"sche_id"					=>		$shedules,
						"sat_7_8"					=>		$data["teacher_sat_7_8"],
						"sat_8_10"					=>		$data["teacher_sat_8_10"],
						"sat_10_12"					=>		$data["teacher_sat_10_12"],
						"sat_1_2"					=>		$data["teacher_sat_1_2"],
						"sat_2_4"					=>		$data["teacher_sat_2_4"],
						"sat_4_5"					=>		$data["teacher_sat_4_5"],
						"sat_5_7"					=>		$data["teacher_sat_5_7"],
						"sat_7_8_1"					=>		$data["teacher_sat_7_8_1"],
			
						"sun_7_8"					=>		$data["teacher_sun_7_8"],
						"sun_8_10"					=>		$data["teacher_sun_8_10"],
						"sun_10_12"					=>		$data["teacher_sun_10_12"],
						"sun_1_2"					=>		$data["teacher_sun_1_2"],
						"sun_2_4"					=>		$data["teacher_sun_2_4"],
						"sun_4_5"					=>		$data["teacher_sun_4_5"],
						//"sun_5_7"					=>		$data["teacher_sun_5_7"],
						"sun_7_8_1"					=>		$data["teacher_sat_7_8_1"],
						"created_date"				=>		new Zend_Date(),
				);
				$this->_name="tbl_teacher_sche";
				$this->insert($teacher);
			}
			
			if($session==1){
				$room = array(
						"sche_id"					=>		$shedules,
			
						"mon_7_8"					=>		$data["room_mon_7_8"],
						"mon_8_10"					=>		$data["room_mon_8_10"],
						"mon_10_12"					=>		$data["room_mon_10_12"],
			
						"tur_7_8"					=>		$data["room_tue_7_8"],
						"tur_8_10"					=>		$data["room_tue_8_10"],
						"tur_10_12"					=>		$data["room_tue_10_12"],
			
						"wed_7_8"					=>		$data["room_wed_7_8"],
						"wed_8_10"					=>		$data["room_wed_8_10"],
						"wed_10_12"					=>		$data["room_wed_10_12"],
			
						"thu_7_8"					=>		$data["room_thu_7_8"],
						"thu_8_10"					=>		$data["room_thu_8_10"],
						"thu_10_12"					=>		$data["room_thu_10_12"],
			
						"fri_7_8"					=>		$data["room_fri_7_8"],
						"fri_8_10"					=>		$data["room_fri_8_10"],
						"fri_10_12"					=>		$data["room_fri_10_12"],
				);
			
				$this->_name="tbl_room_sche";
				$this->insert($room);
			}elseif ($session==2){
				$room = array(
						"sche_id"					=>		$shedules,
			
						"mon_1_2"					=>		$data["room_mon_1_2"],
						"mon_2_4"					=>		$data["room_mon_2_4"],
						"mon_4_5"					=>		$data["room_mon_4_5"],
			
						"tur_1_2"					=>		$data["room_tue_1_2"],
						"tur_2_4"					=>		$data["room_tue_2_4"],
						"tur_4_5"					=>		$data["room_tue_4_5"],
			
						"wed_1_2"					=>		$data["room_wed_1_2"],
						"wed_2_4"					=>		$data["room_wed_2_4"],
						"wed_4_5"					=>		$data["room_wed_4_5"],
			
						"thu_1_2"					=>		$data["room_thu_1_2"],
						"thu_2_4"					=>		$data["room_thu_2_4"],
						"thu_4_5"					=>		$data["room_thu_4_5"],
			
						"fri_1_2"					=>		$data["room_fri_1_2"],
						"fri_2_4"					=>		$data["room_fri_2_4"],
						"fri_4_5"					=>		$data["room_fri_4_5"],
			
				);
				$this->_name="tbl_room_sche";
				$this->insert($room);
			}elseif ($session==3){
				$room = array(
						"sche_id"					=>		$shedules,
			
						"mon_5_7"					=>		$data["room_mon_5_7"],
						"mon_7_8_1"					=>		$data["room_mon_7_8_1"],
			
						"tur_5_7"					=>		$data["room_tue_5_7"],
						"tur_7_8_1"					=>		$data["room_tue_7_8_1"],
			
						"wed_5_7"					=>		$data["room_wed_5_7"],
						"wed_7_8_1"					=>		$data["room_tue_7_8_1"],
			
						"thu_5_7"					=>		$data["room_thu_5_7"],
						"thu_7_8_1"					=>		$data["room_thu_7_8_1"],
			
						"fri_5_7"					=>		$data["room_fri_5_7"],
						"fri_7_8_1"					=>		$data["room_fri_7_8_1"],
				);
				$this->_name="tbl_room_sche";
				$this->insert($room);
			}else{
			
				$room =array(
						"sche_id"					=>		$shedules,
						"sat_7_8"					=>		$data["room_sat_7_8"],
						"sat_8_10"					=>		$data["room_sat_8_10"],
						"sat_10_12"					=>		$data["room_sat_10_12"],
						"sat_1_2"					=>		$data["room_sat_1_2"],
						"sat_2_4"					=>		$data["room_sat_2_4"],
						"sat_4_5"					=>		$data["room_sat_4_5"],
						"sat_5_7"					=>		$data["room_sat_5_7"],
						"sat_7_8_1"					=>		$data["room_sat_7_8_1"],
			
						"sun_7_8"					=>		$data["room_sun_7_8"],
						"sun_8_10"					=>		$data["room_sun_8_10"],
						"sun_10_12"					=>		$data["room_sun_10_12"],
						"sun_1_2"					=>		$data["room_sun_1_2"],
						"sun_2_4"					=>		$data["room_sun_2_4"],
						"sun_4_5"					=>		$data["room_sun_4_5"],
						//"sun_5_7"					=>		$data["room_sun_5_7"],
						"sun_7_8_1"					=>		$data["room_sat_7_8_1"],
						"created_date"				=>		new Zend_Date(),
				);
				$this->_name="tbl_room_sche";
				$this->insert($room);
			}
			$db->commit();
		}catch (Exception $e){
			$db->rollBack();
			$e->getMessage();
		}
	}
}
